<template>
  <div>
    <table-box ref="tableBox" show-index no-request :data="tableData" :other-filters="filtersRaw" :table-config="tableConfig" />
    <RewardsAndPunishmentDetail ref="rapd" />
  </div>
</template>
<script>
import RewardsAndPunishmentDetail from './rewardsAndPunishmentDetail'
export default {
  name: 'RewardsAndPunishment',
  components: {
    RewardsAndPunishmentDetail
  },
  props: {
    customerCode: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      tableData: [],
      tableConfig: {
        interfacePath: `${process.env.VUE_APP_BASE_API}/api/v1/rewardPunishmentRoutine/page`,
        hideSearchBar: true,
        tabIndex: 16,
        setting: [
          {
            prop: 'rewardPunishmentCode',
            label: '奖惩编码',
            className: 'btn-green',
            minWidth: 150,
            isButton: true,
            clickFun: this.toDetail
          },
          {
            prop: 'rewardPunishmentName',
            label: '奖惩名称',
            minWidth: 140
          },
          {
            prop: 'fileNumber',
            label: '文件编号',
            minWidth: 130
          },
          {
            prop: 'fileName',
            label: '文件名称',
            minWidth: 130
          },
          {
            prop: 'businessAccountCode',
            label: '业务账号编码',
            minWidth: 130
          },
          {
            prop: 'businessAccountName',
            label: '业务账号名称',
            minWidth: 130
          },
          {
            prop: 'agencyName',
            label: '办事处名称',
            minWidth: 130
          },
          {
            prop: 'agencyType',
            label: '办事处类型',
            minWidth: 120,
            propEnum: {
              appCode: 'slm',
              domainCode: 'marketing',
              dictTypeCode: 'OFFICE_NATURE'
            }
          },
          {
            prop: 'notificationType',
            label: '通报类别',
            minWidth: 100,
            propEnum: {
              appCode: 'slm',
              domainCode: 'marketing',
              dictTypeCode: 'CIRCULATE_TYPE'
            }
          },
          {
            prop: 'rewardPunishmentCategory',
            label: '奖惩类别',
            minWidth: 100,
            propEnum: {
              appCode: 'slm',
              domainCode: 'marketing',
              dictTypeCode: 'SHOP_REWARD_PUNISH_TYPE'
            }
          },
          {
            prop: 'rewardAmount',
            label: '奖励金额',
            minWidth: 100
          },
          {
            prop: 'plannedPenaltyAmount',
            label: '计划处罚金额',
            minWidth: 100
          },
          {
            prop: 'penaltyType',
            label: '处罚金额类型',
            minWidth: 100,
            propEnum: {
              appCode: 'slm',
              domainCode: 'marketing',
              dictTypeCode: 'FINE_TYPE'
            }
          },
          {
            prop: 'warehouseOccupancyFee',
            label: '库房占用费',
            minWidth: 100
          },
          {
            prop: 'isDerate',
            label: '是否有减免',
            minWidth: 100,
            propEnum: {
              appCode: 'slm',
              domainCode: 'marketing',
              dictTypeCode: 'BOOLEANS'
            }
          },
          {
            prop: 'derateAmount',
            label: '减免金额',
            minWidth: 100
          },
          {
            prop: 'actualPenaltyAmount',
            label: '实际扣款金额',
            minWidth: 100
          },
          {
            prop: 'financeDate',
            label: '财务日期',
            minWidth: 100
          },
          {
            prop: 'dataSource',
            label: '数据来源',
            minWidth: 100,
            formatData: ({
              dataSource
            }) => {
              if (dataSource === 1) return '手工新增'
              else return 'BPM'
            }
          }
        ]
      }
    }
  },
  computed: {
    filtersRaw() {
      return [{ id: 'customerCode', property: 'customerCode', value: this.customerCode, operator: '=' }]
    }
  },
  mounted() {
    this.refreshTableData()
  },
  methods: {
    toDetail(row) {
      this.$refs.rapd.openDialog(row.id)
    },
    refreshTableData(type) {
      this.$nextTick(() => {
        this.$refs.tableBox.initTableData(type)
      })
    }
  }
}
</script>
